package global;

import java.util.Random;

import model.Agencia;
import simulacao.GeneratedInfo;

public class Global {

	public static final int NUM_TERMINAIS = 3;
	
	public static final int NUM_ACESSOS = 1000;
	
	public static final int NUM_DIGITOS = 2;
	
	public static int NUM_AGENCIAS = 1;
	
	public static int PORTA = 1025;
	
	public static GeneratedInfo geraDados(Agencia agencia) {
		Random random = new Random();
		GeneratedInfo gi = new GeneratedInfo();
		int i = agencia.getCodigo();
		
		if(random.nextInt(10) < 7 || Global.NUM_AGENCIAS == 1) {
			gi.setCodAgencia(agencia.getCodigo());
			i = random.nextInt(10) + 1;
			gi.setCodConta(correctValue(i));
		} else {
			while(i == agencia.getCodigo() || i == 0) {
				i = random.nextInt(NUM_AGENCIAS);
			}

			gi.setCodAgencia(i);
			i = random.nextInt(10) + 1;
			gi.setCodConta(correctValue(i));
		}
		
		return gi;
	}
	
	private static String correctValue(int value) {
		String s = String.valueOf(value);
		
		while(s.length() < Global.NUM_DIGITOS) {
			s = "0" + s;
		}
		
		return s;
	}
	
	public static String correctDecimal(int value) {
		String s = String.valueOf(value);
		
		while(s.length() < 2) {
			s = "0" + s;
		}
		
		return s;
	}

}
